﻿using HighDiveEngine.Resources;
using NUnit.Framework;

namespace UnitTestHighDive
{
    [TestFixture]
    public class UnitTestDiveCodeDifficultyCalculator
    {
        private double diff1;
        private double diff2;
        private double diff3;
        private double diff4;
        private double diff5;

        [SetUp]
        public void SetUp()
        {
             diff1 = DiveCodeDifficultyCalculator.Instance.GetDifficulty("204B", 3);
             diff2 = DiveCodeDifficultyCalculator.Instance.GetDifficulty("5124D", 5);
             diff3 = DiveCodeDifficultyCalculator.Instance.GetDifficulty("600A", 10);
             diff4 = DiveCodeDifficultyCalculator.Instance.GetDifficulty("404B", 1);
             diff5 = DiveCodeDifficultyCalculator.Instance.GetDifficulty("312B", 1);
        }

        [Test]
        public void TestGetDifficulty()
        {            
            Assert.AreEqual(2.3, diff2);
            Assert.AreEqual(3.0, diff4);
            Assert.AreEqual(1.8, diff5);
        }

        [Test]
        public void TestFreePositionOnlyInTwistingDivesConstraint()
        {
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("612D", 7));
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("404D", 7));
        }

        [Test]
        public void TestArmstandNoRotationConstraint()
        {
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("600B", 7));
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("601A", 7));
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("610A", 7));
        }

        [Test]
        public void TestHalfSomersaultAndTwistsConstraint()
        {
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("6111D", 7));
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("6112D", 7));
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("6212D", 7));
            
        }

        [Test]
        public void TestOneToOneAndAHalfSomersaultsAndTwistsConstraint()
        {
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("6121A", 7));
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("6122B", 7));
            Assert.Throws(typeof(DiveCodeException), () => DiveCodeDifficultyCalculator.Instance.GetDifficulty("6232A", 7));
        }
    }
}
